package thread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 苏西西
 * Date: 2023-08-29
 * Time: 21:10
 */
class Counter2{
    public int count = 0;
    synchronized public void add(){
        count++;
    }
    public void add2(){
        count++;
    }

}

public class ThreadD13_1 {
    public static void main(String[] args) {
        Counter2 counter2 = new Counter2();
        Thread t1 = new Thread(() ->{
            for (int i = 0; i < 5000; i++) {
                counter2.add();
            }
        });
        Thread t2 = new Thread(() ->{
            for (int i = 0; i < 5000; i++) {
                counter2.add2();
            }
        });
        t1.start();
        t2.start();

        try {
            t1.join();
            t2.join();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(counter2.count);
    }
}
